package view.ui 
{
	import comp.display.ControlTabItem;
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	/**
	 * 左侧列表顶部的内容控制部分，包括导航，搜索控件，以及内容浏览快速定位的控件等等
	 * @author Qi Donghui
	 */
	public class InfoControl extends Sprite 
	{
		private var _cont:Sprite;
		
		private var _bg:MovieClip;
		
		private var _arrTabs:Array = [];
		
		private var _currentTab:ControlTabItem;
		
		public function InfoControl() 
		{
			addEventListener(Event.ADDED_TO_STAGE, onAddToStage);	
		}		
		
		///////////////////////////////////////
		/////事件处理
		//////////////////////////////////////
		private function onAddToStage(e:Event):void 
		{
			removeEventListener(Event.ADDED_TO_STAGE, onAddToStage);
			_bg = new SKtabBg();
			//_bg.y = 47;
			this.y = 47;
			_bg.width = 600;
			addChild(_bg);
			onStageResize();
			stage.addEventListener(Event.RESIZE, onStageResize);
			
			var tab1:ControlTabItem = new ControlTabItem(this, 20, 16, "我的单词");
			tab1.selected = true;		
			_currentTab = tab1;
			var tab2:ControlTabItem = new ControlTabItem(this, 20 + 79 + 6, 16, "我的搜索");
			var tab3:ControlTabItem = new ControlTabItem(this, 20 + (79 + 6)*2, 16,"我的收藏");
			var tab4:ControlTabItem = new ControlTabItem(this, 20 + (79 + 6) * 3, 16, "我的创意");
			
			_arrTabs[_arrTabs.length] = tab1;
			_arrTabs[_arrTabs.length] = tab2;
			_arrTabs[_arrTabs.length] = tab3;
			_arrTabs[_arrTabs.length] = tab4;
			
			for (var i:int = 0; i < _arrTabs.length; i++) 
			{
				var item:ControlTabItem = _arrTabs[i];
				item.addEventListener(MouseEvent.CLICK, onTabClick);		
			}
		}
		
		private function onTabClick(e:MouseEvent):void 
		{
			currentTab = e.currentTarget as ControlTabItem;
		}
		
		private function onStageResize(evt:Event = null):void
		{
			if (stage.stageWidth < 960) this.x = 0;
			else {
				this.x = stage.stageWidth * 0.5 - 480;
			}
		}
		
		public function get currentTab():ControlTabItem 
		{
			return _currentTab;
		}
		
		public function set currentTab(value:ControlTabItem):void 
		{
			if (value == _currentTab) return;
			_currentTab.selected = false;
			_currentTab = value;	
			_currentTab.selected = true;
		}
		
	}

}